package com.itany.corejava.code13_jdbc;

/**
 * @author MissChen
 * @version 1.0
 * @date 2023 年12月12日 16:45
 */
public class Emp {
    private Integer id;
    private String name;
    private Double salary;

    //直接通过外键字段维护
    private Integer deptId;

    //对于主外键关系，在Java中一般使用对象来进行维护
    // 上面deptId对于的t_dept表中的主键，主要用于将当前表与t_dept表进行管理
    // 在Java中，下面用的对象，相当于将当前对象与Dept对象进行关联，此时的属性可以直接使用对象的属性来维护，而不需要使用外键字段
    private Dept dept;
    public Emp() {
    }

    public Emp(String name, Double salary, Integer deptId) {
        this.name = name;
        this.salary = salary;
        this.deptId = deptId;
    }

    public Emp(Integer id, String name, Double salary, Integer deptId) {
        this.id = id;
        this.name = name;
        this.salary = salary;
        this.deptId = deptId;
    }

    public Emp(String name, Double salary, Dept dept) {
        this.name = name;
        this.salary = salary;
        this.dept = dept;
    }

    public Emp(Integer id, String name, Double salary, Dept dept) {
        this.id = id;
        this.name = name;
        this.salary = salary;
        this.dept = dept;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getSalary() {
        return salary;
    }

    public void setSalary(Double salary) {
        this.salary = salary;
    }

    public Integer getDeptId() {
        return deptId;
    }

    public void setDeptId(Integer deptId) {
        this.deptId = deptId;
    }

    public Dept getDept() {
        return dept;
    }

    public void setDept(Dept dept) {
        this.dept = dept;
    }

    // @Override
    // public String toString() {
    //     return "Emp{" +
    //             "id=" + id +
    //             ", name='" + name + '\'' +
    //             ", salary=" + salary +
    //             ", deptId=" + deptId +
    //             '}';
    // }


    @Override
    public String toString() {
        return "Emp{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", salary=" + salary +
                ", dept=" + dept +
                '}';
    }
}
